using System;

namespace Se.Framework.Common.Config
{
    public abstract class ConfigurationValues
    {
        #region values

        public virtual string ServiceUser { get; protected set; }
        public virtual string ServicePassword { get; protected set; }
        public virtual int MaxRecentProfiles { get; protected set; }//int.MaxValue 
        public virtual int MaxRecentWalls { get; protected set; }// = int.MaxValue
        public virtual string DebugSid { get; protected set; }// = "E117151";
        public virtual string EmployeeImageUrl { get; protected set; }// = "E117151";
        public virtual string BulkEmployeeImageUrl { get; protected set; }// = "E117151";
        public virtual int SystemUserId { get; protected set; }// = -1;
        public virtual int MaxSuccessors { get; protected set; }// = 8;
        public virtual string LogOutUrl { get; protected set; }// = "~/Default.aspx";
        public virtual string DashboardUrl { get; protected set; }// = "http://vnjcardashbu01:7001/Viewer.aspx?Dd_ContentId=41b13cd5-dfd8-4529-8d16-9528e4829782&Dd_ContentType=Dashboard&Dd_ViewerFeatures=IsLogoVisible=false;IsToolbarVisible=false;IsNavigationVisible=false";
        public virtual string ScoreCardUrl { get; protected set; }// = "http://vnjcardashbu01:7001/Viewer.aspx?Dd_ContentId=41b13cd5-dfd8-4529-8d16-9528e4829782&Dd_ContentType=Dashboard&Dd_ViewerFeatures=IsLogoVisible=false;IsToolbarVisible=false;IsNavigationVisible=false";
        public virtual bool ShowDashboard { get; protected set; }// = false;
        public virtual bool ShowScoreCard { get; protected set; }// = false;
        public virtual string UserGuideFileName { get; protected set; }// = "guide.docx";
        public virtual string RdiServiceUrl { get; protected set; }// = "https://refdata-ct-uat.jpmchase.net/hr";
        public virtual string JanusUrl { get; protected set; }// = "https://janus-sso-uat.jpmorgan.com/sso/action/login";
        public virtual string JanusAppId { get; protected set; }// = "67449CBD-0618-F7A6-D2E4-CFCFC340BA88";
        public virtual string JanusUser { get; protected set; }// = "R522120";
        public virtual string JanusPassword { get; protected set; }// = "jpmc1234";
        public virtual string DeltaUpdateRunTime { get; protected set; }// = "11:00";
        public virtual string BatchServiceUser { get; protected set; }
        public virtual string BatchServicePassword { get; protected set; }
        public virtual string PhotoService { get; protected set; }
        public virtual string BulkPhotoService { get; protected set; }
        public virtual string OrgService { get; protected set; }
        public virtual string ManagerService { get; protected set; }
        public virtual string SearchService { get; protected set; }
        public virtual string BBCService { get; protected set; }
        public virtual bool IsDebugging { get; protected set; }
        public virtual CustomErrorMode CustomErrorsMode { get; protected set; }

        #endregion

        private IConfigurationManager configurationManager;

        protected virtual IConfigurationManager ConfigurationManager
        {
            get
            {
                if (configurationManager == null)
                {
                    if (ObjectRegistry.Current.IsRegistered<IConfigurationManager>())
                    {
                        configurationManager = ObjectRegistry.Current.Resolve<IConfigurationManager>();
                    }
                    else
                    {
                        configurationManager = DefaultConfigurationManager.Instance;
                    }
                }
                return configurationManager;

            }
        }

        public virtual void LoadValues()
        {
            configurationManager = null;
            //load default values
            MaxRecentProfiles = int.MaxValue;
            MaxRecentWalls = int.MaxValue;
            DebugSid = "E117151";
            EmployeeImageUrl = "E117151";
            BulkEmployeeImageUrl = "E117151";
            SystemUserId = -1;
            MaxSuccessors = 8;
            IsDebugging = false;
            LogOutUrl = "~/Default.aspx";
            DashboardUrl = "http://vnjcardashbu01:7001/Viewer.aspx?Dd_ContentId=41b13cd5-dfd8-4529-8d16-9528e4829782&Dd_ContentType=Dashboard&Dd_ViewerFeatures=IsLogoVisible=false;IsToolbarVisible=false;IsNavigationVisible=false";
            ScoreCardUrl = "http://vnjcardashbu01:7001/Viewer.aspx?Dd_ContentId=41b13cd5-dfd8-4529-8d16-9528e4829782&Dd_ContentType=Dashboard&Dd_ViewerFeatures=IsLogoVisible=false;IsToolbarVisible=false;IsNavigationVisible=false";
            ShowDashboard = false;
            ShowScoreCard = false;
            UserGuideFileName = "guide.docx";
            RdiServiceUrl = "https://refdata-ct-uat.jpmchase.net/hr";
            JanusUrl = "https://janus-sso-uat.jpmorgan.com/sso/action/login";
            JanusAppId = "67449CBD-0618-F7A6-D2E4-CFCFC340BA88";
            JanusUser = "R522120";
            JanusPassword = "jpmc1234";
            DeltaUpdateRunTime = "11:00";
            CustomErrorsMode = CustomErrorMode.Default;

            IConfigurationManager manager = ConfigurationManager;
            manager.ExecuteIfExists("MaxRecentProfiles", n => { MaxRecentProfiles = n; }, int.MaxValue);
            manager.ExecuteIfExists("MaxRecentWalls", n => { MaxRecentWalls = n; }, int.MaxValue);
            manager.ExecuteIfExists("SystemUserId", n => { SystemUserId = n; }, -1);
            manager.ExecuteIfExists("MaxSuccessors", n => { MaxSuccessors = n; }, 8);

            manager.ExecuteIfExists("DebugSid", s => { DebugSid = s; });
            manager.ExecuteIfExists("IsDebugging", b => { IsDebugging = b; }, false);
            manager.ExecuteIfExists("EmployeeImageUrl", s => { EmployeeImageUrl = s; });
            manager.ExecuteIfExists("BulkEmployeeImageUrl", s => { BulkEmployeeImageUrl = s; });
            manager.ExecuteIfExists("ServiceUser", s => { ServiceUser = s; });
            manager.ExecuteIfExists("ServicePassword", s => { ServicePassword = s; });
            manager.ExecuteIfExists("BatchServiceUser", s => { BatchServiceUser = s; });
            manager.ExecuteIfExists("BatchServicePassword", s => { BatchServicePassword = s; });
            manager.ExecuteIfExists("PhotoService", s => { PhotoService = s; });
            manager.ExecuteIfExists("BulkPhotoService", s => { BulkPhotoService = s; });
            manager.ExecuteIfExists("OrgService", s => { OrgService = s; });
            manager.ExecuteIfExists("HierarchyService", s => { ManagerService = s; });
            manager.ExecuteIfExists("SearchService", s => { SearchService = s; });
            manager.ExecuteIfExists("BBCService", s => { BBCService = s; });
            manager.ExecuteIfExists("LogOutUrl", s => { LogOutUrl = s; });
            manager.ExecuteIfExists("DundasDashboardUrl", s => { DashboardUrl = s; });
            manager.ExecuteIfExists("DundasScorecardUrl", s => { ScoreCardUrl = s; });

            manager.ExecuteIfExists("DeltaUpdateRunTime", s => { DeltaUpdateRunTime = s; });
            manager.ExecuteIfExists("RdiServiceUrl", s => { RdiServiceUrl = s; });
            manager.ExecuteIfExists("JanusUrl", s => { JanusUrl = s; });
            manager.ExecuteIfExists("JanusUser", s => { JanusUser = s; });
            manager.ExecuteIfExists("JanusPassword", s => { JanusPassword = s; });
            manager.ExecuteIfExists("JanusAppId", s => { JanusAppId = s; });
            manager.ExecuteIfExists("ShowDashboard", b => { ShowDashboard = b; }, false);
            manager.ExecuteIfExists("ShowScoreCard", b => { ShowScoreCard = b; }, false);
            manager.ExecuteIfExists("UserGuideFileName", s => { UserGuideFileName = s; });

            string customErrorModeValue = manager.AppSettings["CustomErrorMode"];
            CustomErrorMode customErrorMode = CustomErrorMode.Default;
            if (!string.IsNullOrWhiteSpace(customErrorModeValue) && Enum.TryParse<CustomErrorMode>(customErrorModeValue, out customErrorMode))
            {
                CustomErrorsMode = customErrorMode;            
            }
        }

    }
}